package com.znf.biz.system.controller;

import com.znf.base.Result;
import com.znf.biz.system.dto.req.LoginReqDto;
import com.znf.biz.system.dto.resp.CaptchaRespDto;
import com.znf.biz.system.dto.resp.LoginRespDto;
import com.znf.biz.system.dto.resp.PubKeyRespDto;
import com.znf.biz.system.service.IAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Data
@Slf4j
@Api(tags = "认证接口")
@RestController
@RequestMapping("/auth")
public class AuthController {

    private final IAuthService authService;

    @ApiOperation("获取验证码")
    @GetMapping("/getCaptcha")
    public Result<CaptchaRespDto> getCaptcha() throws IOException {
        CaptchaRespDto captcha = authService.getCaptcha();
        return Result.success(captcha);
    }

    @ApiOperation("获取公钥")
    @GetMapping("/getPubKey")
    public Result<PubKeyRespDto> getPubKey() {
        PubKeyRespDto pubKey = authService.getPubKey();
        return Result.success(pubKey);
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result<LoginRespDto> login(@RequestBody LoginReqDto param) {
        LoginRespDto data = authService.login(param);
        return Result.success(data);
    }

}
